<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="商品名称" prop="oname">
        <el-input
          v-model="queryParams.oname"
          placeholder="请输入商品名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['order:order:export']"
        >导出</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <right-toolbar :showSearch.sync="showSearch" @queryTable="listSell"></right-toolbar>
    </el-row>

    <el-table :row-class-name="tableRowClassName" v-loading="loading" :data="Data" @selection-change="handleSelectionChange">
<!--      <el-table-column type="selection" width="55" align="center" />-->
      <el-table-column label="商品id" align="center" prop="commodity.cid" />
      <el-table-column label="商品名称" align="center" prop="commodity.cname" />
      <el-table-column label="订单总数" align="center" prop="total_orders" />
      <el-table-column label="商品总数" align="center" prop="total_order_count" />
      <el-table-column label="商品总金额" align="center" prop="total_order_amount" />

    </el-table>

<!--    <pagination-->
<!--      v-show="total>0"-->
<!--      :total="total"-->
<!--      :page.sync="queryParams.pageNum"-->
<!--      :limit.sync="queryParams.pageSize"-->
<!--      @pagination="listSell"-->
<!--    />-->

  </div>
</template>

<script>
import { getSell } from "@/api/order/order";
import {getCategorys} from "@/api/commodity/commodity";

export default {
  name: "Order",
  data() {
    return {
      dataTable:[],
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 订单信息表格数据
      orderList: [],
      //售出管理
      sellList:[],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      Data:[],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        oname:null,
      },

      //表单参数
      order: {
        commodity: {
          cid: null,
          cname: null,
        },
      },
    };
  },
  created() {
    this.listSell();
  },
  methods: {

      //指定行颜色
      tableRowClassName: function({ row, rowIndex }) {
        console.log(row, 'row');
        console.log("rowIndex", rowIndex);
        if (row.total_order_count >= 5) {
          return 'rowbg';
        }
    },

    //售出管理
    listSell() {
      this.loading = true;
      let params = {};
      if (this.queryParams.oname) {
        params.commodity = { cname: this.queryParams.oname };
      }
      getSell(params).then(response => {
        // alert(JSON.stringify(response))
        this.Data = response.rows; // 更新数据列表
        this.total = response.total; // 更新总条数
        this.loading = false;
        // alert(JSON.stringify(response))
      }).catch(error => {
        console.error('获取数据失败：', error);
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.order = {
        oid: null,
        total_order_count: 0,
        total_order_amount: 0,
        total_orders: 0,

        commodity:{
          cid: null,
        },
        deleted: null

      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.listSell();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.oid)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },

    /** 导出按钮操作 */
    handleExport() {
      this.download('order/order/export', {
        ...this.queryParams
      }, `order_${new Date().getTime()}.xlsx`)
    }
  }
};

</script>

<style>
.rowbg{
  background: rgba(255, 254, 192, 0.65) !important;
}
</style>
